﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VietPremier.Areas.AdminCP.Models;
using MvcLibrary.Repository;
using System.IO;

namespace VietPremier.Areas.AdminCP
{
    public class AdminFeedBackController : Controller
    {
        #region "Index"
        public ActionResult Index()
        {
            using (dbVietPremierDataContext db = new dbVietPremierDataContext())
            {
                FeedBackModel model = new FeedBackModel();

                foreach (var feedback in db.EntityFeedBacks)
                {
                    model.listFeedBack.Add(new FeedBack()
                    {
                        Id = feedback.Id,
                        Email = feedback.Email,
                        DateCreate = feedback.DateCreate,
                        Body = feedback.Body,
                        Page = feedback.Page
                    });
                }
                return View(model);
            }
        }
        #endregion //index

        #region "Delete"
        public string Delete(int id)
        {
            try
            {
                dbVietPremierDataContext db = new dbVietPremierDataContext();
                EntityFeedBack item = db.EntityFeedBacks.Where(p => p.Id == id).Single();
                db.EntityFeedBacks.DeleteOnSubmit(item);
                db.SubmitChanges();
                return "Ok";
            }
            catch
            {
                return "Error";

            }

        }
        #endregion

        #region "Edit"
        public ActionResult View(int idFeedback)
        {
            using (dbVietPremierDataContext db = new dbVietPremierDataContext())
            {
                FeedBack model = new FeedBack();
                EntityFeedBack feedback = db.EntityFeedBacks.FirstOrDefault(o => o.Id == idFeedback);
                if (feedback != null)
                {
                    model.Id = feedback.Id;
                    model.DateCreate = feedback.DateCreate;
                    model.Email = feedback.Email;
                    model.Body = feedback.Body;
                    model.Page = feedback.Page;
                    return PartialView(model);
                }
                return PartialView();
            }

        }
        #endregion //edit
    }
}
